<?php
/** 
 * Created by RisingSun. 
 * User: MarkSpace 
 * Date: 20210822
 * Time: 11:05 
 * 营销中心管理
 */
namespace app\market\controller;

use  Mscore\Core\Controller;
use  Mscore\Core\Log;
use  Mscore\Core\Lib\Upload;
use  app\admin\model\Login as LoginModel;

class CommonController extends Controller{
   
    /**
     * 初始化自动连接方法
     * @param array $sysmod 
     * @param array $where 
    */
    public function __construct()  
    {    
        $this->login = (new LoginModel)->isLoggedin();
        if(isset($this->login['code'])&&$this->login['code']==401){
            echo json_encode($this->login);
            Header("Location:".config('server.login_url'));
            exit;
        }
    }   
    
    /**
     * 编辑器上传图片
     * @param array $singleadd 
     * @param array $where 
     */
    public function editor_upload_img($file='file'){
      $url='static/upload/'.$file.'/'.date('Ym',time());
      if(!is_dir($url)){
         mkdir($url, 0777, true); 
      }
      $icon = (new Upload)->Uploadfile($_FILES['file'],$url);
      Log::write(sprintf("UPDATEFILE uid=【%s】,name=【%s】,file=【%s】", $this->login['uid'], $this->login['user_name'], $icon),Log::NOTICE,Log::FILE,LOG_PATH.'upfile/'.date("y_m_d").".log");
      echo '{"code":200,"msg":"成功上传","data":{"src":"/'.$icon.'"}}';
    }

}